package AccessDB;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import model.Administrador;
import model.Professor;

public class AdministradorDAO {

	private Connection con;
	
	public AdministradorDAO(){
		super();
		con = ConnectionDB.getInstance().getConnection();
	}
	
	public Administrador retornaAdministrador(String cpf) throws SQLException{
		
		PreparedStatement stmt = con.prepareStatement("select * from Administrador where cpfAdmin = ?");
		stmt.setString(1, cpf);
		stmt.execute();
		
		ResultSet rs = stmt.getResultSet();
		
		Administrador admin = gerarAdministrador(rs);
		
		return admin;
		
	}
	
	private Administrador gerarAdministrador(ResultSet rs) throws SQLException{
		
		if(rs.next()){
			Administrador admin = new Administrador();
			admin.setNomeCompleto(rs.getString("nomeCompleto"));
			admin.setNomeUsual(rs.getString("nomeUsual"));
			admin.setCpf(rs.getString("cpfAdmin"));

			return admin;
		}
		return null;
	}
}
